<template>
	<div id="app">
		<keep-alive :include="catchPages">
			<router-view v-if="$route.meta.keepAlive" class="keppAlive"></router-view>
		</keep-alive>
		<router-view v-if="!$route.meta.keepAlive"></router-view>
	</div>
</template>
<script>
	import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
	export default {
		name: "app",
		data() {
			return {
				first: null
			}
		},
		computed: {
			...mapState(["catchPages"])
		},
		mounted() {
			this.withdrawFrom(this);
		},
		methods: {
			withdrawFrom(that) {
				mui.init({
					keyEventBind: {
						backbutton: true //关闭back按键监听
					}
				});
				//处理逻辑：1秒内，连续两次按返回键，则退出应用；
				mui.back = function() {
					var route = that.$route.name;
					if(route == "home" || route == "find" || route == "about") {
						//首次按键，提示  再按一次退出应用
						if(!that.first) {
							that.first = new Date().getTime(); //记录第一次按下回退键的时间
							mui.toast('再按一次退出应用');
							setTimeout(function() { //2s中后清除
								that.first = null;
							}, 2000);
						} else {
							if(new Date().getTime() - that.first < 2000) { //如果两次按下的时间小于2s，
								plus.runtime.quit(); //那么就退出app
							};
						};
					} else {
						that.$router.go(-1);
					}
				};
			}
		}
	}
</script>

<style scoped lang="scss">
	#app {
		width: 100%;
		height: 100%;
		font-family: "Avenir", Helvetica, Arial, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		background: #FFFFFF;
	}
</style>